# _*_coding:utf-8 _*_
# @Time　　:2021/1/31 16:19
# @Author　 : wangyong
# @File　　  :runAll.py
# @Software  :PyCharm
import os
import time
import unittest
import sys

from ApiTest.api.do_excel import DoExcel

sys.path.append('../')
from ApiTest.utils.HTMLTestRunner_cn import HTMLTestRunner
from ApiTest.conf.project_path import case_dir, report_path, case_data_path,result_list


doExcel = DoExcel(case_data_path)

discover = unittest.defaultTestLoader.discover(case_dir, pattern='test_*.py')

now = time.strftime("%Y-%m-%d_%H_%M_%S")
report_paths = os.path.join(report_path + '自动化回归_' + now + '_result.html')

fp = open(report_paths, "wb")
runner = HTMLTestRunner(title="apiTest测试报告",
                        description="apiTest测试报告，详情见附件",
                        stream=fp,
                        verbosity=2,
                        retry=0,
                        save_last_try=True)
runner.run(discover)
fp.close()
for dic in result_list:
    doExcel.write_excel(dic["module"],dic["case_id"],dic["text"],dic["result"])

doExcel.save_excel()
